package pl.edu.pw.stud.ltrzaska.policy.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;

import pl.edu.pw.stud.ltrzaska.policy.entity.iface.IFilesystemParent;


public class Directory extends FilesystemObject implements IFilesystemParent, Serializable {
	private static final long serialVersionUID = 2635312122058457442L;
	private ArrayList<FilesystemObject> children;

	public Directory() {
		super();
	}

	public ArrayList<FilesystemObject> getChildren() {
		return children;
	}

	public void setChildren(ArrayList<FilesystemObject> children) {
		this.children = children;
	}

	public boolean hasChildren() {
		return (this.children != null && this.children.size() > 0);
	}

	public List<FileObject> findVirtualFsEquivalents(FileObject parentVirtualFsObj) throws FileSystemException {
		List<FileObject> generalResult = super.findVirtualFsEquivalents(parentVirtualFsObj);
		List<FileObject> result = new ArrayList<FileObject>();
		if (generalResult != null) {
			for (FileObject fo : generalResult) {
				if (fo.getType() == FileType.FOLDER) {
					result.add(fo);
				}
			}
		}
		return result;
	}
}
